package com.example.team.service.Imp;

import com.example.team.dao.IJobDao;
import com.example.team.entity.Job;
import com.example.team.service.IJobService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
/**
 *作者：代志雄
 * 2023年10月29日23点44分
 */
//服务接口规范的方法实现
@Service
public class IJobServiceImpl implements IJobService {

    @Autowired
    private IJobDao jobMapper;
    @Override
    public int insertJob(Job job) {
        int jobValue;
        Job job1=new Job();
        job1.setJobName(job.getJobName());
        List<Job> allJob=jobMapper.getAllJob(job1);
        if(allJob.size()>=1){
            jobValue = -1;
        }else {
            jobValue= jobMapper.insertJob(job);
        }
        return jobValue;
    }

    @Override
    public int deleteJob(Job job) {
        int jobValue;
        Job job1=new Job();
        job1.setJobName(job.getJobName());
        List<Job> allJob=jobMapper.getAllJob(job1);
        if(allJob.size()==0){
            jobValue = -1;
        }else {
            jobValue= jobMapper.deleteJob(job);
        }
        return jobValue;
    }

    @Override
    public int updateJob(Job job) {
        int jobValue;
        Job job1=new Job();
        job1.setJobName(job.getJobName());
        List<Job> allJob=jobMapper.getAllJob(job1);
        if(allJob.size()>=1){
            jobValue = -1;
        }else {
            jobValue= jobMapper.updateJob(job);
        }
        return jobValue;
    }

    @Override
    public List<Job> getAllJob(Job job) {
        return jobMapper.getAllJob(job);
    }

    @Override
    public Job getJob(Job job) {
        return jobMapper.getJob(job);
    }
}
